/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package business;


import data.Requirement;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.MessageDrivenContext;
import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 * trida zajistuje odeslani zprav, ktere jsou v databzi v urcitou dobu
 * @author stana
 */
@Stateless
public class Timer  {

    @EJB private business.RequirementFacade ejbFacade;
    private MessageDrivenContext _context;
    SmsGateway smsGateway;
    YRWeather yr=new YRWeather();

    @Schedule(hour="17",minute="5")
    private void task() //public pro testy
    {
        
        Date actualDate=new Date();
        List<Requirement> requirements=ejbFacade.findByDate(actualDate);
        for(Requirement r:requirements)
        {
            System.out.println(r.getPlace());
            sendSms(r);
        }
        
    }

    private void sendSms(Requirement r)
    {
        smsGateway=new O2Gateway();
        smsGateway.sendSms(yr.getWeather(r.getLatitude(), r.getLongitude()), String.valueOf(r.getPhoneNumber()));

    }

}
